using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace DD.Data.SQL
{
    public static class CartManager
    {
        public static void UpdateQty(int Quantity, int Unique_Id)
        {
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_UPDATE_CART_QTY", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter qty = new SqlParameter("@QTY", Quantity);
            qty.Direction = ParameterDirection.Input;
            com.Parameters.Add(qty);

            SqlParameter uid = new SqlParameter("@UNIQUE_ID", Unique_Id);
            uid.Direction = ParameterDirection.Input;
            com.Parameters.Add(uid);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();



        }

        public static void AddItemToCart(int pid, int sid, string did, int qty)
        {
            Visitors.Visitor vis = new DD.Visitors.Visitor();
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_ADD_ITEM_TO_CART", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter pid1 = new SqlParameter("@PID", pid);
            pid1.Direction = ParameterDirection.Input;
            pid1.SqlDbType = SqlDbType.Int;
            com.Parameters.Add(pid1);

            SqlParameter sid1 = new SqlParameter("@SID", sid);
            sid1.Direction = ParameterDirection.Input;
            sid1.SqlDbType = SqlDbType.Int;
            com.Parameters.Add(sid1);

            SqlParameter did1 = new SqlParameter("@DID", did);
            did1.Direction = ParameterDirection.Input;
            did1.SqlDbType = SqlDbType.NVarChar;
            com.Parameters.Add(did1);

            SqlParameter uid1 = new SqlParameter("@UID", vis.UserId);
            uid1.Direction = ParameterDirection.Input;
            uid1.SqlDbType = SqlDbType.Int;
            com.Parameters.Add(uid1);

            SqlParameter qty1 = new SqlParameter("@QTY", qty);
            qty1.Direction = ParameterDirection.Input;
            qty1.SqlDbType = SqlDbType.Int;
            com.Parameters.Add(qty1);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();


        }

        public static DataSet GetCartDS()
        {
            Visitors.Visitor vis = new DD.Visitors.Visitor();
            DataSet cartDs = new DataSet();

            SqlConnection conn = new SqlConnection();

            conn = DD.Data.SQL.DataManager.GetConnection();
            SqlCommand com = new SqlCommand();
            com.Connection = conn;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "GetUserCart";

            SqlParameter param = new SqlParameter();
            param.Direction = ParameterDirection.Input;
            param.ParameterName = "@UserId";
            param.SqlDbType = SqlDbType.Int;
            param.Value = vis.UserId;
            com.Parameters.Add(param);

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            da.Fill(cartDs);

            return cartDs;
        }
    }
}
